package com.penghk.springbootdemo.service.impl;

import com.penghk.springbootdemo.service.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;

@Service
public class RedisServiceImpl implements RedisService {

        @Resource
        private RedisTemplate<String,Object> redisTemplate;

        @Autowired
        private StringRedisTemplate stringRedisTemplate;

        @Resource(name = "stringRedisTemplate")
        ValueOperations<String , String> ops;

        public void set(String key, Object value) {
            ValueOperations<String,Object> vo = redisTemplate.opsForValue();
//            ops.set(key , value.toString());
            vo.set(key, value);
        }

        public Object get(String key) {
            ValueOperations<String,Object> vo = redisTemplate.opsForValue();
            return vo.get(key);

        }


        public void test() {
            ListOperations<String, Object> lo = redisTemplate.opsForList();
            lo.leftPush("list1", "value1");
            lo.leftPush("list1", "value2");
            lo.leftPush("list1", "value3");
        }

}
